<template>
  <div>
    <div class="alert" @click="cancel" v-if="showAlertBool"></div>
    <div class="alert-win" v-if="showAlertBool">
      <div class="font14 cl333">举报【{{ detailsTitle }}】，并填写举报原因</div>
      <div class="textareaCss">
        <el-input type="textarea" :rows="5" placeholder="这里输入举报内容，请如实举报" v-model="reportText" />
      </div>
      <div class="but">
        <el-button @click="cancel">取消</el-button>
        <el-button type="primary" @click="send" :loading="submitLoading">发送</el-button>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { requirementReport } from '@/api/api'
import {ElMessage} from "element-plus";
const emit = defineEmits(['cancelEmit'])
const props = defineProps({
  detailsTitle: {
    type: String,
    default: null
  },
  requirementId: {
    type: String,
    default: null
  },
  showAlertBool: {
    type:Boolean,
    default: false
  }
});
const submitLoading = ref(false)
const reportText = ref('')
const cancel = () => {
  reportText.value = ''
  emit('cancelEmit')
}
const send = () => {
  if (!reportText.value) {
    ElMessage.warning('请输入举报描述')
    return false
  }
  submitLoading.value = true
  requirementReport({
    content : reportText.value,
    requirementId: props.requirementId
  }).then((res:any) => {
    submitLoading.value = false
    if (res.code === 200) {
      ElMessage.success('举报成功')
      cancel()
    } else {
      ElMessage.error(res.msg)
    }
  }).catch((err:any) => {
    console.log(err)
    submitLoading.value = false
  })
}
</script>
<style scoped>
.but{
  text-align: right;
}
.alert{
  z-index: 198;
  background-color: rgb(0, 0, 0);
  opacity: 0.5;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  position: fixed;
}
.alert-win{
  position: fixed;
  background: #fff;
  z-index: 199;
  padding: 20px;
  border-radius: 8px;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
  width: 430px;
  box-sizing: border-box;
}
.font14 {
  font-size: 14px;
}
.cl333 {
  color: #333;
}
.textareaCss{
  margin-top: 15px;
  margin-bottom: 15px;
}
</style>